package com.bytz.modules.cms.productLine.service.impl;

import cn.hutool.core.collection.CollectionUtil;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.bytz.modules.cms.productLine.entity.ProductLineLevelLimit;
import com.bytz.modules.cms.productLine.mapper.ProductLineLevelLimitMapper;
import com.bytz.modules.cms.productLine.service.IProductLineLevelLimitService;
import org.springframework.stereotype.Service;

import java.util.Collection;
import java.util.Collections;
import java.util.List;
import java.util.stream.Collectors;

/**
 * <p>
 * 莱宝CMS—产品线管理—产品线等级商品限制表 服务实现类
 * </p>
 *
 * @author KyleWang
 * @since 2022-10-10
 */
@Service
public class ProductLineLevelLimitServiceImpl extends ServiceImpl<ProductLineLevelLimitMapper, ProductLineLevelLimit> implements IProductLineLevelLimitService {

    @Override
    public List<String> getByProductNumbers(Collection<String> productNumbers) {
        if (CollectionUtil.isEmpty(productNumbers)) {
            return Collections.emptyList();
        }

        return lambdaQuery()
                .select(ProductLineLevelLimit::getProductNumber)
                .in(ProductLineLevelLimit::getProductNumber, productNumbers)
                .list()
                .stream().map(ProductLineLevelLimit::getProductNumber)
                .collect(Collectors.toList());
    }

    @Override
    public List<String> getByProductNumbersAndProductLineIdAndLevelId(Collection<String> productNumbers, Collection<String> productLineLevelIds) {
        if (productNumbers.isEmpty()) {
            return Collections.emptyList();
        }
        return lambdaQuery().select(ProductLineLevelLimit::getProductNumber)
                .in(ProductLineLevelLimit::getProductNumber, productNumbers)
                .in(ProductLineLevelLimit::getProductLineLevelId, productLineLevelIds)
                .list()
                .stream()
                .map(ProductLineLevelLimit::getProductNumber)
                .collect(Collectors.toList());
    }

    @Override
    public void removeByLevelId(String id) {
        lambdaUpdate().eq(ProductLineLevelLimit::getProductLineLevelId, id).remove();
    }
}